package com.flipdf2.serialize.ppml.element;

import java.awt.geom.Rectangle2D;

import org.jdom.Element;
import org.jdom.Namespace;

import com.flipdf2.serialize.ppml.PPMLException;

public class PPMLPageDesign {
	public static final String NAME = "PAGE_DESIGN";
	
	private Rectangle2D.Double trimBox;
	private Rectangle2D.Double bleedBox;
	
	public Element toXML(Namespace defaultNamespace) {
		Element root = null;
		if (defaultNamespace != null) {
			root = new Element(NAME, defaultNamespace);
		} else {
			root = new Element(NAME);	
		}

		if (trimBox != null) {
			root.setAttribute("TrimBox", trimBox.x + " " + trimBox.y
				+ " " + trimBox.width + " " + trimBox.height);
		}
		
		if (bleedBox != null) {
			root.setAttribute("BleedBox", bleedBox.x + " " + bleedBox.y
				+ " " + bleedBox.width + " " + bleedBox.height);
		}
		
		return root;
	}
	
	public void check() throws PPMLException {
		if (trimBox == null) {
			throw PPMLException.getInstance(PPMLException.REQUIRED_ATTRIBUTE_LOST, "TrimBox");
		}
	}

	public Rectangle2D.Double getBleedBox() {
		return bleedBox;
	}

	public void setBleedBox(Rectangle2D.Double bleedBox) {
		this.bleedBox = bleedBox;
	}

	public Rectangle2D.Double getTrimBox() {
		return trimBox;
	}

	public void setTrimBox(Rectangle2D.Double trimBox) {
		this.trimBox = trimBox;
	}
}
